import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class LoginGUI{
     JFrame frame;
	 JPanel mainpanel, waitingpanel;
	 JLabel PlayerName, waiting;
	 JTextField Name;
	 JButton login, start;
	 Client theClient;
	
	public LoginGUI(Client _theClient){
		frame = new JFrame("Welcome to the game!");
		mainpanel = new JPanel();
		theClient = _theClient;
		
		login = new JButton("Log In");
		PlayerName = new JLabel("Please enter your name:");
		Name = new JTextField(10);
		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(BorderLayout.CENTER, mainpanel);		
		mainpanel.setLayout(new GridLayout(2, 2));
		
		mainpanel.add(PlayerName);
		mainpanel.add(Name);
		mainpanel.add(login);
		
		waitingpanel = new JPanel(); 
		
		login.addActionListener(new loginListener());
		
		frame.setSize(400,150);
		frame.setVisible(true);
	
	}
	class loginListener implements ActionListener{
	   public void actionPerformed(ActionEvent event) {
		//send the playername to the server
	    waiting = new JLabel("Waiting for other players...");
	    waitingpanel.add(waiting);
		frame.repaint();
	  }
	}
	
	public void startplay(){
		waiting.setText("Ready to play the game?");
		start = new JButton("Start Game");
		start.addActionListener(new startListener());
		mainpanel.add(start);
		frame.repaint();
	}
	
	class startListener implements ActionListener{
		public void actionPerformed(ActionEvent event){
		frame.dispose();
		theClient.StartPlaying();
	}
}

